__author__ = 'wangjc'

from PageObjects.BasePage import BasePage

class Swipe(BasePage):
    # @property
    # def get_window_size(self):
    #     """获取窗口大小"""
    #     return self.driver.get_window_size()
    #
    # @property
    # def x(self):
    #     """获取x轴宽度"""
    #     return self.get_window_size['width']
    #
    # @property
    # def y(self):
    #     """获取y轴高度"""
    #     return self.get_window_size['height']

    # x = x()
    # y = y()

    def swipe_left(self, scale=0.8):
            """
            向左滑动
            :param scale: 滑动距离所占比例
            起点：（1+scale）x/2,  0.5y
            终点：（1-scale）x/2,  0.5y
            """
            self.driver.swipe(self.x * (1 + scale) / 2, self.y() * 0.5,
                              self.x * (1 - scale) / 2, self.y() * 0.5)

    def swipe_right(self, scale=0.8):
        """
        向右滑动
        :param scale: 滑动距离所占比例
        起点：（1-scale）x/2,  0.5y
        终点：（1+scale）x/2,  0.5y
        """
        self.driver.swipe(self.x * (1 - scale) / 2, self.y * 0.5,
                          self.x * (1 + scale) / 2, self.y * 0.5)

    def swipe_up(self, scale=0.5):
        """
        向上滑动
        :param scale: 滑动距离所占比例
        起点：0.5x,  (1+scale)*y/2
        终点：0.5x,  (1-scale)*y/2
        """
        self.driver.swipe(self.x * 0.5, int(int(self.y) * (1 + scale) /2),
                          self.x * 0.5, int(int(self.y) * (1 - scale) /2))

    def swipe_down(self, scale=0.2):
        """
        向下滑动
        :param scale: 滑动距离所占比例
        起点：0.5x,  (1-scale)*y/2
        终点：0.5x,  (1+scale)*y/2
        """
        self.driver.swipe(self.x * 0.5, self.y * (1 - scale) / 2,
                          self.x * 0.5, self.y * (1 + scale) / 2)
        # self.driver.swipe(self.x * 0.5, self.y * 0.25,
        #                    self.x * 0.5, self.y * 0.75)


    def swipe_up_to_location(self, ex, ey):
        """
        向上滑动到指定位置
        :param scale: 滑动距离所占比例
        起点：sx,  sy
        终点：ex,  ey
        """
        self.driver.swipe(self.x * 0.5, self.y * (1 + 0.2) / 2, self.x * 0.5, ey)